package com.sunyifeng.ch25;

/**
 * 计算机
 */
public class ComputerImpl implements ComputerPart {

    ComputerPart[] parts;

    public ComputerImpl() {
        // 初始化鼠标、键盘、显示器，computer在main方法中调用
        parts = new ComputerPart[]{new MouseImpl(), new KeyboardImpl(), new MonitorImpl()};
    }


    @Override
    public void accept(ComputerPartVisitor computerPartVisitor) {
        for (int i = 0; i < parts.length; i++) {
            parts[i].accept(computerPartVisitor);
        }
        // computer的accept方法在main中调用
        computerPartVisitor.visit(this);
    }
}